package org.jeecg.modules.task.controller;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.CommonSendStatus;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.modules.activity.entity.ActivityInfo;
import org.jeecg.modules.activity.service.IActivityInfoService;
import org.jeecg.modules.clues.entity.Clues;
import org.jeecg.modules.clues.service.ICluesService;
import org.jeecg.modules.content.entity.ConContentExtras;
import org.jeecg.modules.content.entity.ConContentVersion;
import org.jeecg.modules.content.entity.ContentInfo;
import org.jeecg.modules.content.service.IConContentExtrasService;
import org.jeecg.modules.content.service.IConContentVersionService;
import org.jeecg.modules.content.service.IContentInfoService;
import org.jeecg.modules.engine.service.IWorkflowEngineService;
import org.jeecg.modules.innertopic.entity.InnerTopic;
import org.jeecg.modules.innertopic.service.IInnerTopicService;
import org.jeecg.modules.interview.entity.InterviewUnion;
import org.jeecg.modules.interview.service.IInterviewInfoService;
import org.jeecg.modules.interview.service.IInterviewUnionService;
import org.jeecg.modules.recommend.entity.RecommandInfo;
import org.jeecg.modules.recommend.service.IRecommandService;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.service.*;
import org.jeecg.modules.task.entity.*;
import org.jeecg.modules.task.service.*;
import org.jeecg.modules.workflow.entity.WorkFlowBase;
import org.jeecg.modules.workflow.entity.WorkFlowBaseAssign;
import org.jeecg.modules.workflow.entity.WorkFlowChildNodeAssignDept;
import org.jeecg.modules.workflow.entity.WorkFlowParentNode;
import org.jeecg.modules.workflow.service.IWorkFlowBaseAssignService;
import org.jeecg.modules.workflow.service.IWorkFlowBaseService;
import org.jeecg.modules.workflow.service.IWorkFlowParentNodeService;
import org.jeecg.util.DateTimeUtil;
import org.jeecg.util.SeqGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskDecorator;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import java.util.*;

/**
 * @Description: 任务基础信息
 * @author: wufanxin
 * @date: 2021-06-12
 * @version: V1.0
 */
@Slf4j
@RestController
@RequestMapping("/task/taskInfo")
@Api(tags = "任务基础信息")
public class TaskInfoController extends JeecgController<WorkFlowBase, IWorkFlowBaseService> {
	@Autowired
	private IWorkFlowBaseService workFlowBaseService;

	@Autowired
	private IWorkFlowBaseAssignService workFlowBaseAssignService;

	@Autowired
	private ITaskInfoBaseService taskInfoBaseService;

	@Autowired
	private IWorkflowEngineService engineService;

	@Autowired
	private SeqGenerator taskNo;

	@Autowired
	ISysDepartService sysDepartService;
	@Autowired
	ISysUserRoleService sysUserRoleService;

	@Autowired
	private IContentInfoService contentInfoService;

	@Autowired
	private IActivityInfoService activityInfoService;

	@Autowired
	private SeqGenerator contentNo;

	@Autowired
	private SeqGenerator activityNo;

	@Autowired
	ITaskWorkflowStepService stepService;

	@Autowired
	IConContentVersionService versionService;

	@Autowired
	ITaskOperationService operationService;

	@Autowired
	IWorkFlowParentNodeService parentNodeService;

	@Autowired
	ITaskWorkflowMainService taskWorkflowMainService;

	@Autowired
	ITaskWorkflowRejectRemarkService rejectRemarkService;

	@Autowired
	ITaskClueLinkService clueLinkService;

	@Autowired
	IInnerTopicService innerTopicService;

	@Autowired
	ICluesService clueService;

	@Autowired
	ITaskAttachService attachService;

	@Autowired
	ITaskOutLinkService outLinkService;
	@Autowired
	ITaskFeedbackService feedbackService;

	@Autowired
	IConContentBankService conContentBankService;
	@Autowired
	IConContentBankRefService conContentBankRefService;
	@Autowired
	ITaskSyncService taskSyncService;
	@Autowired
	ISysAnnouncementService sysAnnouncementService;
	@Autowired
	ISysAnnouncementSendService sysAnnouncementSendService;
	@Autowired
	ITaskPublishStateService taskPublishStateService;
	@Autowired
	private ISysUserService sysUserService;
	/**
	 * 查询当前可创建的任务流程

	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-查询可创建的任务流程", notes = "查询可创建的任务流程-查询可创建的任务流程")
	@GetMapping(value = "/queryAviWorkflow")
	public Result<?> queryAviWorkflow(HttpServletRequest req) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		QueryWrapper<WorkFlowBaseAssign> assignWrapper = new QueryWrapper<>();
		//查询本级部门是否有上级部门
		List<SysDepart> list = sysDepartService.queryUserDeparts(loginUser.getId());
		//用这个人的所有部门去判断
		list.stream().forEach(item->{
			assignWrapper.or(assign->assign.eq("assign_dept", item.getId()))
					.or(assign->assign.eq("assign_dept", item.getParentId()));
		});

		List<WorkFlowBaseAssign> assignList = workFlowBaseAssignService.list(assignWrapper);
		List<String> ids = new ArrayList<>();
		assignList.stream().forEach(item->{
			ids.add(item.getWorkflowId());
		});
		QueryWrapper<WorkFlowBase> flowWrapper = new QueryWrapper<>();
		flowWrapper.in("workflow_id",ids);

		List<WorkFlowBase> workFlowBaseList = workFlowBaseService.list(flowWrapper);
		return Result.ok(workFlowBaseList);
	}




	/**
	 * 创建任务
	 * TaskInfoBase
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-创建任务", notes = "查询可创建的任务流程-创建任务")
	@PostMapping(value = "/createTask")
	@Transactional
	public Result<?> createTask(HttpServletRequest req, @RequestBody TaskInfoBase taskInfoBase) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		//暂时需要提供 taskName，taskType,workflowId,endTime
		//taskNo 自动生成
		taskInfoBase.setTaskNo(taskNo.next());
		taskInfoBase.setDepartCode(loginUser.getDepartIds());
		taskInfoBaseService.save(taskInfoBase);
		//开启工作流
		engineService.startWorkFlow(taskInfoBase.getWorkflowId(),taskInfoBase.getTaskNo(),loginUser.getId(),StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());

		//根据类型初始化内容或者活动信息
		if(taskInfoBase.getTaskType().equals("0")){
			ContentInfo contentInfo = new ContentInfo();
			contentInfo.setTaskId(taskInfoBase.getTaskNo());
			contentInfo.setTaskName(taskInfoBase.getTaskName());
			contentInfo.setContentNo(contentNo.next());
			contentInfo.setContentTitle(taskInfoBase.getTaskName());
			if(!StringUtils.isEmpty(taskInfoBase.getContentBankId())){
				//如果从内容库选择
				QueryWrapper<ConContentBank> conContentBankQueryWrapper = new QueryWrapper<>();
				conContentBankQueryWrapper.eq("id",taskInfoBase.getContentBankId()).last(" limit 1");
				ConContentBank conContentBank = conContentBankService.getOne(conContentBankQueryWrapper);
				contentInfo.setContent(conContentBank.getContent());
				contentInfo.setContentTitle(conContentBank.getContentTitle());
				contentInfo.setContentIntroduce(conContentBank.getContentIntroduce());
				contentInfo.setContentSubTitle(conContentBank.getContentSubTitle());
				ConContentBankRef conContentBankRef = new ConContentBankRef();
				conContentBankRef.setBankId(taskInfoBase.getContentBankId());
				conContentBankRef.setTaskNo(taskInfoBase.getTaskNo());
				conContentBankRef.setId(UUIDGenerator.generate());
				conContentBankRefService.save(conContentBankRef);
			}
			contentInfoService.save(contentInfo);
		}else{
			ActivityInfo activityInfo = new ActivityInfo();
			activityInfo.setTaskId(taskInfoBase.getTaskNo());
			activityInfo.setTaskName(taskInfoBase.getTaskName());
			activityInfo.setActivityNo(activityNo.next());
			if(!StringUtils.isEmpty(taskInfoBase.getContentBankId())){
				//如果从内容库选择
				QueryWrapper<ConContentBank> conContentBankQueryWrapper = new QueryWrapper<>();
				conContentBankQueryWrapper.eq("id",taskInfoBase.getContentBankId()).last(" limit 1");
				ConContentBank conContentBank = conContentBankService.getOne(conContentBankQueryWrapper);
				activityInfo.setContent(conContentBank.getContent());
				activityInfo.setActivityTitle(conContentBank.getContentTitle());
				activityInfo.setActivityIntroduction(conContentBank.getContentIntroduce());
				activityInfo.setActivitySubTitle(conContentBank.getContentSubTitle());
				ConContentBankRef conContentBankRef = new ConContentBankRef();
				conContentBankRef.setBankId(taskInfoBase.getContentBankId());
				conContentBankRef.setTaskNo(taskInfoBase.getTaskNo());
				conContentBankRef.setId(UUIDGenerator.generate());
				conContentBankRefService.save(conContentBankRef);
			}
			activityInfoService.save(activityInfo);
		}

		//保存任务线索关联
		if(null != taskInfoBase.getClueIdList() && taskInfoBase.getClueIdList().size()>0){
			List<TaskClueLink> clueLinks = new ArrayList<>();
			taskInfoBase.getClueIdList().stream().forEach(item->{
				TaskClueLink clueLink = new TaskClueLink();
				clueLink.setClueId(item);
				clueLink.setTaskNo(taskInfoBase.getTaskNo());
				clueLinks.add(clueLink);
			});
			clueLinkService.saveBatch(clueLinks);
		}

		//处理保存任务附件
		if(null != taskInfoBase.getAttachList() && taskInfoBase.getAttachList().size()>0){
			List<TaskAttach> attacheList = taskInfoBase.getAttachList();
			attacheList.stream().forEach(item->{
				item.setTaskNo(taskInfoBase.getTaskNo());
			});
			attachService.saveBatch(attacheList);
		}

		//处理保存任务外链
		if(null != taskInfoBase.getOutLinkList() && taskInfoBase.getOutLinkList().size()>0){
			List<TaskOutLink> outLinkList = taskInfoBase.getOutLinkList();
			outLinkList.stream().forEach(item->{
				item.setTaskNo(taskInfoBase.getTaskNo());
			});
			outLinkService.saveBatch(outLinkList);
		}

		return Result.ok();
	}


	/**
	 * 任务列表
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-任务列表", notes = "查询可创建的任务流程-任务列表")
	@GetMapping(value = "/queryTaskList")
	public Result<?> queryTaskList(HttpServletRequest req, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
								   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		Map<String,Object> param  = new HashMap<>();
		Result<IPage<Map<String, Object>>> result = new Result<IPage<Map<String, Object>>>();
		Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNo,
				pageSize);
		param.put("start", (pageNo - 1) * 10);
		param.put("limit",pageSize);
		param.put("userId",loginUser.getId());
		List<SysDepart> departList = sysDepartService.queryUserDeparts(loginUser.getId());
		param.put("departs",departList);

		QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<SysUserRole>();
		sysUserRoleQueryWrapper.eq("user_id",loginUser.getId());
		List<SysUserRole> roleList = sysUserRoleService.list(sysUserRoleQueryWrapper);
		param.put("roles",roleList);
		//查询是否根据部门配置，查询是否根据角色配置
		QueryWrapper<TaskWorkflowAssignDepert> taskWorkflowAssignDepertQueryWrapper = new QueryWrapper<>();

		List<Map<String, Object>> resultList = taskInfoBaseService.queryTaskList(param);
		page.setRecords(resultList);
		page.setTotal(taskInfoBaseService.queryTaskListTotal(param));
		result.setSuccess(true);
		result.setResult(page);

		return result;
	}

	/**
	 * 任务列表（已处理） 改成已经编辑
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-任务列表（已处理）", notes = "查询可创建的任务流程-任务列表（已处理）")
	@GetMapping(value = "/queryHisTaskList")
	public Result<?> queryHisTaskList(HttpServletRequest req, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
								   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		Map<String,Object> param  = new HashMap<>();
		Result<IPage<Map<String, Object>>> result = new Result<IPage<Map<String, Object>>>();
		Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNo,
				pageSize);
		param.put("start", (pageNo - 1) * 10);
		param.put("limit",pageSize);
		param.put("userId",loginUser.getId());

		List<Map<String, Object>> resultList = taskInfoBaseService.queryHisTaskList(param);
		page.setRecords(resultList);
		page.setTotal(taskInfoBaseService.queryHisTaskListTotal(param));
		result.setSuccess(true);
		result.setResult(page);

		return result;
	}

@ApiOperation(value = "任务基础信息-任务列表（已处理）", notes = "查询可创建的任务流程-任务列表（已处理）")
	@GetMapping(value = "/queryHisTaskList2")
	public Result<?> queryHisTaskList2(HttpServletRequest req, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
								   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		Map<String,Object> param  = new HashMap<>();
		Result<IPage<Map<String, Object>>> result = new Result<IPage<Map<String, Object>>>();
		Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNo,
				pageSize);
		param.put("start", (pageNo - 1) * 10);
		param.put("limit",pageSize);
		param.put("userId",loginUser.getId());

		List<Map<String, Object>> resultList = taskInfoBaseService.queryHisTaskList2(param);
		page.setRecords(resultList);
		page.setTotal(taskInfoBaseService.queryHisTaskListTotal2(param));
		result.setSuccess(true);
		result.setResult(page);

		return result;
	}





	/**
	 * 任务授权
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-任务授权", notes = "查询可创建的任务流程-任务授权")
	@GetMapping(value = "/grantTask")
	public Result<?> grantTask(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo,@RequestParam(name="childNodeId")
			String childNodeId,@RequestParam(name="grantUserId") String grantUserId ,@RequestParam(name="grantUserName") String grantUserName ) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		engineService.grant(taskNo,childNodeId,loginUser.getId(),grantUserId,grantUserName,
				StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());
		return Result.OK();
	}


	/**
	 * 任务回退，找到上一个处理人 授权过去
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-任务授权", notes = "查询可创建的任务流程-任务授权")
	@GetMapping(value = "/taskRecall")
	public Result<?> taskRecall(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//		Map<String, Object> showTaskMap = taskInfoBaseService.queryQuickStart(taskNo);

		QueryWrapper<TaskWorkflowStep> stepQueryWrapper = new QueryWrapper<>();
		stepQueryWrapper.eq("task_no",taskNo).orderByDesc("create_time").last(" limit 1");

		List<TaskWorkflowStep> stepList = stepService.list(stepQueryWrapper);
		TaskWorkflowStep step = stepList.get(0);
//		QueryWrapper<SysUser> queryWrapperSysUser =  new QueryWrapper<>();
//		queryWrapperSysUser.eq("id",step.getDealUserId());
		engineService.grantReverse(taskNo,step.getChildNodeId(),loginUser.getId(),step.getDealUserId(),StringUtils.isEmpty(sysUserService.getById(step.getDealUserId()).getRealname())?sysUserService.getById(step.getDealUserId()).getUsername():sysUserService.getById(step.getDealUserId()).getRealname(),
				StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());
		return Result.OK();
	}

	/**
	 * 提交任务
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-提交任务", notes = "查询可创建的任务流程-提交任务")
	@PostMapping(value = "/processTask")
	public Result<?> processTask(HttpServletRequest req,@RequestBody Map<String,Object> requestMap) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		String childNodeId = requestMap.get("childNodeId").toString();
		String taskNo = requestMap.get("taskNo").toString();
		operationService.saveTaskInfo(requestMap);
		engineService.process(taskNo,childNodeId,loginUser.getId(),StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());
		return Result.OK();
	}



	/**
	 * 驳回任务
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-驳回任务", notes = "查询可创建的任务流程-驳回任务")
	@GetMapping(value = "/rejectTask")
	public Result<?> rejectTask(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo,@RequestParam(name="childNodeId")
			String childNodeId ,@RequestParam(name="remark") String remark) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		TaskWorkflowRejectRemark reject = new TaskWorkflowRejectRemark();
		reject.setChildNodeId(childNodeId);
		reject.setTaskNo(taskNo);
		reject.setRemark(remark);
		rejectRemarkService.save(reject);
		int code = engineService.reject(taskNo,childNodeId,loginUser.getId(),StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname(),remark);
		if(code == 202){
			return Result.error("请在流程节点配置中配置该驳回节点的退回节点");
		}
		return Result.OK();
	}


	/**
	 * 获取任务信息
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-获取任务信息", notes = "查询可创建的任务流程-获取任务信息")
	@GetMapping(value = "/queryTaskInfo")
	public Result<?> queryTaskInfo(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		QueryWrapper<TaskInfoBase> taskInfoBaseQueryWrapper = new QueryWrapper<>();
		taskInfoBaseQueryWrapper.eq("task_no",taskNo).last(" limit 1");
		TaskInfoBase  taskInfoBase = taskInfoBaseService.getOne(taskInfoBaseQueryWrapper);
		return Result.OK(taskInfoBase);
	}

	/**
	 * 获取任务内部选题信息
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-获取任务内部选题信息", notes = "查询可创建的任务流程-获取任务内部选题信息")
	@GetMapping(value = "/queryTaskInnerTopic")
	public Result<?> queryTaskInnerTopic(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		QueryWrapper<TaskInfoBase> taskInfoBaseQueryWrapper = new QueryWrapper<>();
		taskInfoBaseQueryWrapper.eq("task_no",taskNo).last(" limit 1");
		TaskInfoBase  taskInfoBase = taskInfoBaseService.getOne(taskInfoBaseQueryWrapper);
		//查询内部选题信息
		QueryWrapper<InnerTopic> innerTopicQueryWrapper = new QueryWrapper<>();
		innerTopicQueryWrapper.eq("id",taskInfoBase.getTopicIds()).last(" limit 1");
		return Result.OK(innerTopicService.getOne(innerTopicQueryWrapper));
	}

	/**
	 * 获取任务附件信息
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-获取任务附件信息", notes = "查询可创建的任务流程-获取任务附件信息")
	@GetMapping(value = "/queryTaskAttach")
	public Result<?> queryTaskAttach(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		QueryWrapper<TaskAttach> attachQueryWrapper = new QueryWrapper<>();
		attachQueryWrapper.eq("task_no",taskNo);
		List<TaskAttach>  attachList = attachService.list(attachQueryWrapper);
		return Result.OK(attachList);
	}


	/**
	 * 更新任务附件信息
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-更新任务附件信息", notes = "查询可创建的任务流程-更新任务附件信息")
	@PostMapping(value = "/updateTaskAttach")
	public Result<?> updateTaskAttach(HttpServletRequest req,@RequestBody TaskInfoBase taskInfoBase) {

		QueryWrapper<TaskAttach> attachQueryWrapper = new QueryWrapper<>();
		attachQueryWrapper.eq("task_no",taskInfoBase.getTaskNo());
		attachService.remove(attachQueryWrapper);
		if(null != taskInfoBase.getAttachList() && taskInfoBase.getAttachList().size()>0){
			List<TaskAttach> attacheList = taskInfoBase.getAttachList();
			attacheList.stream().forEach(item->{
				item.setTaskNo(taskInfoBase.getTaskNo());
			});
			attachService.saveBatch(attacheList);
		}

		return Result.OK();
	}

	/**
	 * 获取任务外链
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-获取任务外链", notes = "查询可创建的任务流程-获取任务外链")
	@GetMapping(value = "/queryTaskAttachOutLink")
	public Result<?> queryTaskAttachOutLink(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		QueryWrapper<TaskOutLink> outLinkQueryWrapper = new QueryWrapper<>();
		outLinkQueryWrapper.eq("task_no",taskNo);
		List<TaskOutLink>  outLinkList = outLinkService.list(outLinkQueryWrapper);
		return Result.OK(outLinkList);
	}


	/**
	 * 更新任务外链
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-更新任务外链", notes = "查询可创建的任务流程-更新任务外链")
	@PostMapping(value = "/updateTaskOutLink")
	public Result<?> updateTaskOutLink(HttpServletRequest req,@RequestBody TaskInfoBase taskInfoBase) {

		QueryWrapper<TaskOutLink> outLinkQueryWrapper = new QueryWrapper<>();
		outLinkQueryWrapper.eq("task_no",taskInfoBase.getTaskNo());
		outLinkService.remove(outLinkQueryWrapper);
		//处理保存任务外链
		if(null != taskInfoBase.getOutLinkList() && taskInfoBase.getOutLinkList().size()>0){
			List<TaskOutLink> outLinkList = taskInfoBase.getOutLinkList();
			outLinkList.stream().forEach(item->{
				item.setTaskNo(taskInfoBase.getTaskNo());
			});
			outLinkService.saveBatch(outLinkList);
		}
		return Result.OK();
	}


	/**
	 * 获取任务线索信息
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-获取任务线索信息", notes = "查询可创建的任务流程-获取任务线索信息")
	@GetMapping(value = "/queryTaskClueInfo")
	public Result<?> queryTaskClueInfo(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		//线索信息
		QueryWrapper<TaskClueLink> linkQueryWrapper = new QueryWrapper<>();
		linkQueryWrapper.eq("task_no",taskNo);
		List<TaskClueLink> clueLinkList =  clueLinkService.list(linkQueryWrapper);
		List<String> clueLinkIds = new ArrayList<>();
		clueLinkList.stream().forEach(item->{
			clueLinkIds.add(item.getClueId());
		});
		List<Clues> clueList = new ArrayList<>();
		QueryWrapper<Clues> cluesQueryWrapper =  new QueryWrapper<>();
		if(null != clueLinkIds && clueLinkIds.size()>0){
			cluesQueryWrapper.in("id",clueLinkIds);
			clueList = clueService.list(cluesQueryWrapper);
		}
		return Result.OK(clueList);
	}

	/**
	 *  更新任务线索信息
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-更新任务线索信息", notes = "查询可创建的任务流程-更新任务线索信息")
	@PostMapping(value = "/updateTaskClueInfo")
	public Result<?> updateTaskClueInfo(HttpServletRequest req,@RequestBody TaskInfoBase taskInfoBase) {
		QueryWrapper<TaskClueLink> linkQueryWrapper = new QueryWrapper<>();
		linkQueryWrapper.eq("task_no",taskInfoBase.getTaskNo());
		clueLinkService.remove(linkQueryWrapper);
		if(null != taskInfoBase.getClueIdList() && taskInfoBase.getClueIdList().size()>0){
			List<TaskClueLink> clueLinks = new ArrayList<>();
			taskInfoBase.getClueIdList().stream().forEach(item->{
				TaskClueLink clueLink = new TaskClueLink();
				clueLink.setClueId(item);
				clueLink.setTaskNo(taskInfoBase.getTaskNo());
				clueLinks.add(clueLink);
			});
			clueLinkService.saveBatch(clueLinks);
		}
		return Result.OK();
	}




	/**
	 * 获取任务内容信息
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-获取任务内容信息", notes = "查询可创建的任务流程-获取任务内容信息")
	@GetMapping(value = "/queryTaskContentInfo")
	public Result<?> queryTaskContentInfo(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		QueryWrapper<TaskInfoBase> taskInfoBaseQueryWrapper = new QueryWrapper<>();
		taskInfoBaseQueryWrapper.eq("task_no",taskNo).last(" limit 1");
		TaskInfoBase  taskInfoBase = taskInfoBaseService.getOne(taskInfoBaseQueryWrapper);
		Object obj;
		if(taskInfoBase.getTaskType().equals("0")){
			QueryWrapper<ContentInfo> contentInfoQueryWrapper = new QueryWrapper<>();
			contentInfoQueryWrapper.eq("task_id",taskNo).orderByDesc("create_time").last(" limit 1");
			obj = contentInfoService.getOne(contentInfoQueryWrapper);
		}else{
			QueryWrapper<ActivityInfo> activityInfoQueryWrapper = new QueryWrapper<>();
			activityInfoQueryWrapper.eq("task_id",taskNo).last(" limit 1");
			obj = activityInfoService.getOne(activityInfoQueryWrapper);
		}
		return Result.OK(obj);
	}


	/**
	 * 获取任务内容附加信息信息
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-获取任务内容附加信息信息", notes = "查询可创建的任务流程-获取任务内容附加信息信息")
	@GetMapping(value = "/queryTaskContentAdditionalInfo")
	public Result<?> queryTaskContentAdditionalInfo(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		return Result.OK(operationService.queryContentAdditionByTask(taskNo));
	}

	/**
	 * 获取相关推荐
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-获取相关推荐", notes = "查询可创建的任务流程-获取相关推荐")
	@GetMapping(value = "/queryRecommend")
	public Result<?> queryRecommend(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		return Result.OK(operationService.queryRecommandByTask(taskNo));
	}


	/**
	 * 查询任务流转记录
	 * @param req
	 * @param taskNo
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-查询任务流转记录", notes = "查询可创建的任务流程-查询任务流转记录")
	@GetMapping(value = "/queryTaskStep")
	public Result<?> queryTaskStep(HttpServletRequest req,@RequestParam String taskNo ) {

		QueryWrapper<TaskWorkflowStep> stepQueryWrapper = new QueryWrapper<>();
		stepQueryWrapper.eq("task_no",taskNo).orderByAsc("create_time");

		//查询任务信息
		QueryWrapper<TaskWorkflowMain> taskInfoBaseQueryWrapper = new QueryWrapper<>();
		taskInfoBaseQueryWrapper.eq("task_no",taskNo).last(" limit 1");
		TaskWorkflowMain taskInfoBase = taskWorkflowMainService.getOne(taskInfoBaseQueryWrapper);

		List<TaskWorkflowStep> stepList = stepService.list(stepQueryWrapper);
		if(!StringUtils.isEmpty(taskInfoBase.getCurrentNodeId())){
			//如果任务没有结束，查询当前节点信息
			QueryWrapper<WorkFlowParentNode> parentNodeQueryWrapper = new QueryWrapper<>();
			parentNodeQueryWrapper.eq("node_id",taskInfoBase.getCurrentNodeId()).last(" limit 1");
			WorkFlowParentNode  parentNode = parentNodeService.getOne(parentNodeQueryWrapper);
			TaskWorkflowStep tempStepInfo = new TaskWorkflowStep();
			tempStepInfo.setOprate("当前节点："+parentNode.getNodeName());
			tempStepInfo.setRemark("当前节点："+parentNode.getNodeName());
			stepList.add(tempStepInfo);
		}
		return Result.OK(stepList);
	}

	/**
	 * 保存任务
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-保存任务", notes = "查询可创建的任务流程-保存任务")
	@PostMapping(value = "/saveTask")
	public Result<?> saveTask(HttpServletRequest req,@RequestBody Map<String,Object> requestMap ) {
		operationService.saveTaskInfo(requestMap);
		return Result.OK();
	}



	/**
	 * 保存任务
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-保存任务", notes = "查询可创建的任务流程-保存任务")
	@PostMapping(value = "/autoSaveTask")
	public Result<?> autoSaveTask(HttpServletRequest req,@RequestBody Map<String,Object> requestMap ) {
		String resutlt = operationService.autoSaveTaskInfo(requestMap);
		if(!resutlt.equals("")){
			return Result.error(resutlt);
		}
		return Result.OK();
	}



	/**
	 * 信息反馈列表（根据taskNo和 childNodeId）
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-信息反馈列表", notes = "查询可创建的任务流程-信息反馈列表")
	@GetMapping(value = "/getFeedbackByTaskAndNode")
	public Result<?> getFeedbackByTaskAndNode(HttpServletRequest req,@RequestParam String taskNo  ) {
		QueryWrapper<TaskFeedback> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("task_no",taskNo);
//		queryWrapper.eq("child_node_id",childNodeId);
		queryWrapper.orderByAsc("create_time");
		List<TaskFeedback> feedbackList = feedbackService.list(queryWrapper);
		return Result.OK(feedbackList);
	}


	/**
	 * 删除信息反馈
	 * @param req id
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-删除信息反馈", notes = "查询可创建的任务流程-删除信息反馈")
	@GetMapping(value = "/deleteFeedback")
	public Result<?> deleteFeedback(HttpServletRequest req,@RequestParam String id ) {
		feedbackService.removeById(id);
		return Result.OK("删除信息反馈成功");
	}



	/**
	 * 保存信息反馈
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-保存信息反馈", notes = "查询可创建的任务流程-保存信息反馈")
	@PostMapping(value = "/saveTaskFeedBack")
	public Result<?> saveTask(HttpServletRequest req,@RequestBody TaskFeedback taskFeedback ) {
		//先删除这个任务节点的
		QueryWrapper<TaskFeedback> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("task_no",taskFeedback.getTaskNo());
		queryWrapper.eq("child_node_id",taskFeedback.getChildNodeId());
		feedbackService.remove(queryWrapper);

		taskFeedback.setId(UUIDGenerator.generate());
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		taskFeedback.setCreateTime(new Date());
		taskFeedback.setCreateBy(loginUser.getUsername());
		feedbackService.save(taskFeedback);
		return Result.OK("保存信息反馈成功");
	}


	/**
	 * 系统内存储新的内容库
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-系统内存储新的内容库", notes = "查询可创建的任务流程-系统内存储新的内容库")
	@PostMapping(value = "/saveConContentBankInter")
	public Result<?> saveConContentBankInter(HttpServletRequest req,@RequestBody ConContentBank conContentBank ) {
		QueryWrapper<ConContentBank> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("task_no",conContentBank.getTaskNo());
		conContentBankService.remove(queryWrapper);

		conContentBank.setId(UUIDGenerator.generate());
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		conContentBank.setAuthorId(loginUser.getId());
		conContentBank.setAuthorName(loginUser.getUsername());
		conContentBank.setState("1");
		conContentBankService.save(conContentBank);
		return Result.OK("保存内容库成功");
	}


	/**
	 * 内容库列表
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-内容库列表", notes = "查询可创建的任务流程-内容库列表")
	@PostMapping(value = "/conContentBankList")
	public Result<?> conContentBankList(HttpServletRequest req, @RequestBody  ConContentBank conContentBank) {
		//先删除这个任务节点的
		QueryWrapper<ConContentBank> queryWrapper = new QueryWrapper<>();
		if(!StringUtils.isEmpty(conContentBank.getContentTitle())){
			queryWrapper.like("content_title",conContentBank.getContentTitle());
		}
		if(!StringUtils.isEmpty(conContentBank.getKeyWords())) {
			queryWrapper.or().like("create_by",conContentBank.getKeyWords());
			queryWrapper.or().like("author_name",conContentBank.getKeyWords());
		}
			queryWrapper.eq("state",conContentBank.getState());
		queryWrapper.orderByDesc("create_time");
		Page<ConContentBank> page = new Page<ConContentBank>(conContentBank.getPageNo(), conContentBank.getPageSize());
		IPage<ConContentBank> pageList = conContentBankService.page(page, queryWrapper);
		return Result.ok(pageList);
	}

	/**
	 * 外部存储新的内容库(authorId 传手机号,authorName 传姓名)
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-外部存储新的内容库", notes = "查询可创建的任务流程-外部存储新的内容库")
	@PostMapping(value = "/saveConContentBankOuter")
	public Result<?> saveConContentBankOuter(HttpServletRequest req,@RequestBody ConContentBank conContentBank ) {
		conContentBank.setCreateBy(conContentBank.getAuthorId());
		conContentBank.setId(UUIDGenerator.generate());
		conContentBank.setState("0");
		conContentBankService.save(conContentBank);
		return Result.OK("保存内容库成功");

	}


	/**
	 * 引用内容库
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-引用内容库", notes = "查询可创建的任务流程-引用内容库")
	@PostMapping(value = "/refContentBank")
	public Result<?> refContentBank(HttpServletRequest req,@RequestBody ConContentBankRef conContentBankRef ) {
		conContentBankRef.setId(UUIDGenerator.generate());
		conContentBankRefService.save(conContentBankRef);
//		QueryWrapper<ConContentBank> queryWrapper = new QueryWrapper<>();
//		queryWrapper.eq("id",conContentBankRef.getBankId()).last(" limit 1");
//		ConContentBank conContentBank = conContentBankService.getOne(queryWrapper);
		return Result.OK("关联成功");
	}



	/**
	 * 审核内容库内容库
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-审核内容库内容库", notes = "查询可创建的任务流程-审核内容库内容库")
	@PostMapping(value = "/auditContentBank")
	public Result<?> auditContentBank(HttpServletRequest req,@RequestBody ConContentBank conContentBank ) {
		UpdateWrapper<ConContentBank> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("id",conContentBank.getId());
		updateWrapper.set("state",conContentBank.getState());
		conContentBankService.update(updateWrapper);
		return Result.OK("审核成功");
	}


	@ApiOperation(value = "任务基础信息-任务加签", notes = "查询可创建的任务流程-任务加签")
	@GetMapping(value = "/grantTaskBoost")
	public Result<?> grantTaskBoost(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo,@RequestParam(name="childNodeId")
			String childNodeId,@RequestParam(name="grantUserId") String grantUserId ,@RequestParam(name="grantUserName") String grantUserName ) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		engineService.grantTaskBoost(taskNo,childNodeId,loginUser.getId(),grantUserId,grantUserName,StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());
		return Result.OK();
	}




	@ApiOperation(value = "任务基础信息-快速开始", notes = "查询可创建的任务流程-快速开始")
	@GetMapping(value = "/quickStart")
	public Result<?> quickStart(HttpServletRequest req,@RequestParam(name="title") String title ) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		//暂时需要提供 taskName，taskType,workflowId,endTime
		//taskNo 自动生成
		TaskInfoBase taskInfoBase = new TaskInfoBase();
		taskInfoBase.setTaskName(title);
		taskInfoBase.setTaskType("0");
		taskInfoBase.setTaskNo(taskNo.next());
		taskInfoBase.setDepartCode(loginUser.getDepartIds());
		taskInfoBase.setWorkflowId("2c9080847b5b9a89017b5b9a89dd0000");
		taskInfoBaseService.save(taskInfoBase);
		//开启工作流
		engineService.startWorkFlow(taskInfoBase.getWorkflowId(),taskInfoBase.getTaskNo(),loginUser.getId(),StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());
		//根据类型初始化内容或者活动信息
		ContentInfo contentInfo = new ContentInfo();
		contentInfo.setTaskId(taskInfoBase.getTaskNo());
		contentInfo.setTaskName(taskInfoBase.getTaskName());
		contentInfo.setContentNo(contentNo.next());
		contentInfo.setContentTitle(title);
		contentInfoService.save(contentInfo);

		//查询返回给前端跳转
		Map<String, Object> showTaskMap = taskInfoBaseService.queryQuickStart(taskInfoBase.getTaskNo());
		grantTask(req,taskInfoBase.getTaskNo(),showTaskMap.get("child").toString(),loginUser.getId(),
				StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());
		return Result.OK(showTaskMap);
	}



	@ApiOperation(value = "任务基础信息-快速直接发布", notes = "查询可创建的任务流程-快速直接发布")
	@GetMapping(value = "/quickStart1")
	public Result<?> quickStart1(HttpServletRequest req,@RequestParam(name="title") String title ) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		//暂时需要提供 taskName，taskType,workflowId,endTime
		//taskNo 自动生成
		TaskInfoBase taskInfoBase = new TaskInfoBase();
		taskInfoBase.setTaskName(title);
		taskInfoBase.setTaskType("0");
		taskInfoBase.setTaskNo(taskNo.next());
		taskInfoBase.setDepartCode(loginUser.getDepartIds());
		taskInfoBase.setWorkflowId("8ac188d18b832c82018bbd3a56a90009");
		taskInfoBaseService.save(taskInfoBase);
		//开启工作流
		engineService.startWorkFlow(taskInfoBase.getWorkflowId(),taskInfoBase.getTaskNo(),loginUser.getId(),StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());
		//根据类型初始化内容或者活动信息
		ContentInfo contentInfo = new ContentInfo();
		contentInfo.setTaskId(taskInfoBase.getTaskNo());
		contentInfo.setTaskName(taskInfoBase.getTaskName());
		contentInfo.setContentNo(contentNo.next());
		contentInfoService.save(contentInfo);

		//查询返回给前端跳转
		Map<String, Object> showTaskMap = taskInfoBaseService.queryQuickStart(taskInfoBase.getTaskNo());
		grantTask(req,taskInfoBase.getTaskNo(),showTaskMap.get("child").toString(),loginUser.getId(),
				StringUtils.isEmpty(loginUser.getRealname())?loginUser.getUsername():loginUser.getRealname());
		return Result.OK(showTaskMap);
	}





	/**
	 * 同步可见与通知
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-同步可见与通知", notes = "查询可创建的任务流程-同步可见与通知")
	@PostMapping(value = "/notifyAndSync")
	public Result<?> notifyAndSync(HttpServletRequest req,@RequestBody Map<String,Object> param ) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		String sendId = UUIDGenerator.generate();
		String taskNo = param.get("taskNo").toString();
		ArrayList<String> ids = (ArrayList<String>)param.get("id");
		List<TaskSync> syncList = new ArrayList<>();
		String userIdStr = "";
		for(String tempId : ids){
			TaskSync tempSync = new TaskSync();
			tempSync.setTaskNo(taskNo);
			tempSync.setId(UUIDGenerator.generate());
			tempSync.setUserId(tempId);
			syncList.add(tempSync);
			userIdStr += (tempId+",");
//			//封装发送
//			SysAnnouncementSend sysAnnouncementSend = new SysAnnouncementSend();
//			sysAnnouncementSend.setAnntId(sendId);
//			sysAnnouncementSend.setId(UUIDGenerator.generate());
//			sysAnnouncementSend.setUserId(tempId);
//			sysAnnouncementSend.setReadFlag("0");
//			sysAnnouncementSends.add(sysAnnouncementSend);
		}
		boolean flag = taskSyncService.saveOrUpdateBatch(syncList);
		if(flag){
			//添加到通知
			SysAnnouncement sysAnnouncement = new SysAnnouncement();
			sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
			sysAnnouncement.setSendStatus(CommonSendStatus.PUBLISHED_STATUS_1);//未发布
			sysAnnouncement.setMsgCategory("1");
			sysAnnouncement.setMsgType("USER");
			sysAnnouncement.setSendTime(new Date());
			sysAnnouncement.setSender(loginUser.getUsername());
			sysAnnouncement.setId(sendId);
			sysAnnouncement.setMsgContent("【任务同步通知】编号："+taskNo);
			sysAnnouncement.setTitile("【任务同步通知】"+loginUser.getUsername()+"通知您，任务："+taskNo+"与您有关，请在同步任务种查看");

			sysAnnouncement.setUserIds(userIdStr);
			sysAnnouncementService.saveAnnouncement(sysAnnouncement);
//			sysAnnouncementSendService.saveBatch(sysAnnouncementSends);

		}
		return Result.OK("同步通知成功");
	}




	/**
	 * 任务列表（同步可见）
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-任务列表（同步可见）", notes = "查询可创建的任务流程-任务列表（同步可见）")
	@GetMapping(value = "/querySyncTaskList")
	public Result<?> querySyncTaskList(HttpServletRequest req, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
									  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		Map<String,Object> param  = new HashMap<>();
		Result<IPage<Map<String, Object>>> result = new Result<IPage<Map<String, Object>>>();
		Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNo,
				pageSize);
		param.put("start", (pageNo - 1) * 10);
		param.put("limit",pageSize);
		param.put("userId",loginUser.getId());

		List<Map<String, Object>> resultList = taskInfoBaseService.querySyncTaskList(param);
		page.setRecords(resultList);
		page.setTotal(taskInfoBaseService.querySyncTaskListTotal(param));
		result.setSuccess(true);
		result.setResult(page);



		return result;
	}

	@ApiOperation(value = "任务基础信息-任务列表（同步可见）", notes = "查询可创建的任务流程-任务列表（同步可见）")
	@GetMapping(value = "/queryFinishedTaskList")
	public Result<?> queryFinishedTaskList(HttpServletRequest req, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
									   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		Map<String,Object> param  = new HashMap<>();
		Result<IPage<Map<String, Object>>> result = new Result<IPage<Map<String, Object>>>();
		Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNo,
				pageSize);
		param.put("start", (pageNo - 1) * 10);
		param.put("limit",pageSize);
		param.put("userId",loginUser.getId());

		List<Map<String, Object>> resultList = taskInfoBaseService.queryFinishedTaskList(param);
		page.setRecords(resultList);
		page.setTotal(taskInfoBaseService.queryFinishedTaskListTotal(param));
		result.setSuccess(true);
		result.setResult(page);



		return result;
	}


	@ApiOperation(value = "任务基础信息-发布信息回显）", notes = "查询可创建的任务流程-发布信息回显")
	@GetMapping(value = "/queryTaskPublishInfo")
	public Result<?> queryTaskPublishInfo(HttpServletRequest req,@RequestParam(name="taskNo") String taskNo) {
		QueryWrapper<TaskPublishState> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("task_no",taskNo);
		queryWrapper.select("channel as `value`,user_id as operateId,user_name as operateName");
		Map<String,Object> retMap = new HashMap<>();
		List<Map<String,Object>> retList = taskPublishStateService.listMaps(queryWrapper);
		if(null != retList && retList.size()>0 ){
			retMap.put("publishChannelHandler",retList);
		}
		ArrayList<String> channelList = new ArrayList<>();
		for(Map<String,Object> temp : retList){
			channelList.add(temp.get("value").toString());
		}
		retMap.put("publishChannel",channelList);
		return Result.OK(retMap);
	}

	/**
	 * 全部任务
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "任务基础信息-全部任务", notes = "查询可创建的任务流程-全部任务")
	@GetMapping(value = "/queryAllTaskList")
	public Result<?> queryAllTaskList(HttpServletRequest req, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
									  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		Map<String,Object> param  = new HashMap<>();
		Result<IPage<Map<String, Object>>> result = new Result<IPage<Map<String, Object>>>();
		Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNo,
				pageSize);
		param.put("start", (pageNo - 1) * 10);
		param.put("limit",pageSize);
		List<Map<String, Object>> resultList = taskInfoBaseService.queryAllTaskList(param);
		page.setRecords(resultList);
		page.setTotal(taskInfoBaseService.queryAllTaskListTotal(param));
		result.setSuccess(true);
		result.setResult(page);
		return result;
	}
	@Autowired
	private ISysBaseAPI sysBaseAPI;
	@GetMapping(value = "/getRole")
	public Result<?> getRole(HttpServletRequest req) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		String role = sysBaseAPI.getRoleIdsByUsername(loginUser.getUsername()).get(0);
		Result<String> result = new Result<String>();

		result.setSuccess(true);
		result.setResult(role);
		return result;
	}




}
